package com.flink.datastreamapi.partition;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class PartitionCustomDemo {

    public static void main(String[] args) throws Exception {
        //        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());

        env.setParallelism(2);

        DataStreamSource<String> socketDS = env.socketTextStream("10.90.100.102", 8888);


        //设置分区
        DataStream<String> myDS = socketDS
                .partitionCustom(
                        //自定义分区的实现类
                        new CustomPartitioner(),
                        //key分组
                        value -> value);


        myDS.print();

        env.execute();
    }
}
